package com.googlecode.svnj.reports;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import org.apache.jackrabbit.util.Text;

/**
 * Helper class to make the tediousness of outputting xml more terse.
 */
public abstract class StaxHelper {
    protected XMLStreamWriter stream;

    /* escape illegal xml chars */
    protected String escape(String xml) {
        return Text.encodeIllegalXMLCharacters(xml);
    }
    protected void text(String txt, boolean escape) throws XMLStreamException {
        if (escape && txt != null)
            txt = Text.encodeIllegalXMLCharacters(txt); 
        stream.writeCharacters(txt);
    }

    protected void elem(String name) throws XMLStreamException {
        stream.writeStartElement(name);
    }
    protected void emptyElem(String name) throws XMLStreamException {
        stream.writeEmptyElement(name);
    }
    protected void att(String name, String val) throws XMLStreamException {
        stream.writeAttribute(name, val);
    }
    protected void end() throws XMLStreamException {
        stream.writeEndElement();
    }    
}
